<?php
/**
 * Created by PhpStorm.
 * User: fengyan
 * Date: 17-11-8
 * Time: 上午9:41
 */

namespace App\Http\Controllers\Admin\Portal;
use Illuminate\Http\Request;

class DocumentPageController extends DocumentController
{
    /**
     * 当前文档模型名
     * @var string
     */
    protected $documentType = 'page';

    /**
     * 更新页面
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
     */
    /*public function edit(Request $request)
    {
        if (strtolower($request->method()) !== 'post') {
            $id = $request->route('id');
            $detail = $this->getServiceRepository()->getDetailById($id);
            $action = 'add';
            if (!empty($id)) {
                $action = 'edit';
            }

            return $this->fetch('edit', [
                'metaTitle' => '更新单网页信息',
                'postUrl'   => get_admin_url('portal/page/edit'),
                'detail'    => $detail,
                'action'    => $action,
            ]);
        }

        $info = $request->input('info', []);

        $cover = get_value($info, 'cover', []);
        $info['cover'] = get_value($cover, 'url', '');
        $info['cover_id'] = get_value($cover, 'id', 0);

        $action = $request->input('action', 'add');

        $this->getServiceRepository()->save($info, $action);

        return $this->success('保存成功');
    }
    */

    /**
     * 默认获取详情方法
     * @param Request $request
     * @return array
     */
    protected function getDetail(Request $request)
    {
        $categoryId = $request->route('category_id');

        $detail = $this->getServiceRepository()->getPageByCategoryId($categoryId);

        return [$detail->id, $categoryId, $detail];
    }
}